const http = require('http')
const fs = require('fs')
const path = require('path')

const server = http.createServer((request, response) => {
  const { pathname } = new URL(request.url, 'http://127.0.0.1:9000')
  const root = __dirname
  fs.readFile(path.resolve(root, `.${pathname}`), (error, data) => {
    if(error) {
      response.setHeader('content-type', 'text/html;charset=utf-8')
      response.statusCode = 500
      response.end('服务错误')
      return
    }
    response.end(data)
  })
})

server.listen(9000, () => {
  console.log('9000端口监听中。。。')
})